//
//  BKXWelcomViewConteoller.swift
//  微博
//
//  Created by 田凯 on 16/4/20.
//  Copyright © 2016年 田凯. All rights reserved.
//

import UIKit
import SDWebImage
import SnapKit
class BKXWelcomViewConteoller: UIViewController {
    
    override func loadView() {
        view = backImageView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        setHeadImageViewAnim()

    }
    func setHeadImageViewAnim(){
    //更新 headImageview 约束
        self.headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        //阻尼动画
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            //重新 布局
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        //发送通知切换根视图
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchDefaultVcNSNotification, object: "welcome")
                })
        }
    
    }

    
    func setupUI(){
    
    view.addSubview(headImageView)
    view.addSubview(messageLabel)
    // 添加约束
        headImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 85, height: 85))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
            
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
    }
    
    
    

    // MARK: - 懒加载控件
    // 背景图片
    private lazy var backImageView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    //头像
    private lazy var headImageView: UIImageView = {
        
        let  head = UIImageView(image: UIImage(named: "avatar_default_big"))
        head.layer.cornerRadius = 85 / 2
        head.clipsToBounds = true
        head.layer.borderColor = ThemeColor.CGColor
        head.layer.borderWidth = 2
        head.sd_setImageWithURL(NSURL(string: BKXUserAccountTools.sharedUserAccountTools.userAccount?.profile_image_url ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        return head
        
        }()
    //欢迎回来 label
    private lazy var messageLabel : UILabel = {
        let lab = UILabel(textcolor: UIColor.grayColor(), textFont: 17)
        lab.textAlignment = .Center
        lab.text = "欢迎回来"
        lab.alpha = 0
        return lab
        }()
    
    
}
